package com.bosssoft.goods.service.impl;

import com.bosssoft.base.entity.PaginationData;
import com.bosssoft.goods.dao.GoodsSearchDao;
import com.bosssoft.goods.domain.dto.GoodSearchDTO;
import com.bosssoft.goods.domain.vo.GoodsSearchQueryVO;
import com.bosssoft.goods.service.GoodsSearchService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 * 商品查询服务接口实现类
 * @author Fang_Sir
 * @date 2021-04-20
 */
@Service
public class GoodsSearchServiceImpl implements GoodsSearchService {
    @Autowired
    private GoodsSearchDao goodsSearchDao;

    @Override
    public PaginationData<GoodSearchDTO> getGoodsAll(GoodsSearchQueryVO query, int page, int size) {
        PageHelper.startPage(page,size);
        List<GoodSearchDTO> list = goodsSearchDao.searchGoodsAll(query);
        PageInfo<GoodSearchDTO> info = new PageInfo<>(list);
        return new PaginationData<>(page,info.getTotal(),info.getList());
    }

    @Override
    public GoodSearchDTO getGoodById(long id) {
        return goodsSearchDao.getGoods(id);
    }

    @Override
    public PaginationData<GoodSearchDTO> searchGoodsByName(String name, int page, int size) {
        PageHelper.startPage(page,size);
        List<GoodSearchDTO> list = goodsSearchDao.searchGoodsByName(name);
        PageInfo<GoodSearchDTO> info = new PageInfo<>(list);
        return new PaginationData<>(page,info.getTotal(),info.getList());
    }

    @Override
    public List<GoodSearchDTO> getGoodsByGoodIds(long[] goodIds) {
        if(goodIds.length <= 0) {
            return new ArrayList<>();
        }
        return goodsSearchDao.getGoodsListByGoodIds(goodIds);
    }
}
